﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE	html PUBLIC	"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html	xmlns="http://www.w3.org/1999/xhtml">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>贵美商城-商品购买页</title>
 <link rel="stylesheet"	type="text/css"	href="css/global.css"	/>
 <link rel="stylesheet"	type="text/css"	href="css/layout.css"	/>
 <script type="text/javascript" src="js/1.11.1.js"></script>
 <script type="text/JavaScript" defer="true">
		function openWindow(){
    var address=window.showModalDialog("address.jsp","","dialogWidth=340px;dialogHeight=270px");
	  document.getElementById("address").value=address;	
		}
  function priceCalc(){
 	var oTr=document.getElementById("priceTable").getElementsByTagName("tr");
  	/**
  	* 因为priceTable从第三个tr开始出现价格列表，倒数第一行结束，所以i=2，i<trObject.length-1
  	* fSum为折扣后总价
  	* fTotal为原总价
  	*/
    var fSum=0;
    var fTotal=0;
		var j=1;
  	for (var i=2;i<oTr.length-1;i++){
  			var oTd=oTr[i].getElementsByTagName("td");
  	  		var fPrice=parseFloat(oTd[j].getElementsByTagName("span")[0].innerHTML.substring(1));//取得原价
			var nCount=parseInt(oTd[j+3].getElementsByTagName("input")[0].value);//取得数量
			var fRealPrice=parseFloat(oTd[j+1].getElementsByTagName("span")[0].innerHTML.substring(1));//取得优惠价
  	  		fSum  +=fRealPrice*nCount;
			fTotal+=fPrice*nCount;
      }	 
   oTr[oTr.length-1].getElementsByTagName("td")[1].innerHTML='￥'+fSum;
   oTr[oTr.length-1].getElementsByTagName("td")[2].innerHTML='你共节省：￥'+(fTotal-fSum);
  	}
  	
  	function remove(oThis,cid){
  	if (confirm("是否删除?")) {
				oFather=oThis.parentNode;
  				oFather.parentNode.parentNode.removeChild(oFather.parentNode);
  				priceCalc();
  			$.ajax({
   			type: "POST",
   			url: "DeletedServlet",
  			data: {id:cid},
  			dataType :"xml",
  			success: function(msg){
   			}	
		}); 
	}else{
	return false;
	}
	}
	
window.onload=priceCalc();
</script>
</head>
<body>
<div id="container">
	<iframe id="header" src="header.jsp" width="980" height="136" frameborder="0" scrolling="no"></iframe>
    <div class="buy">
			<h4><img src="images/mycart.gif" alt="alt" /> <a href="#">全场运费一律2元</a> <a href="#" class="b" onclick="JavaScript:window.open('calc.jsp','计算器','width=200,height=200,toolbar=no,scrollbars=no,menubar=no,screenX=100,screenY=100')">简易计算器</a></h4>
      <table class="buy" cellpadding="0" cellspacing="0">
    	<tbody id="priceTable">
			<tr class="buytitle"><td colspan="6" class="b">确认商品价格与交易条件</td></tr>
      <tr>
        <td class="w364 b">&nbsp;&nbsp;&nbsp;&nbsp;商品名</td>
        <td class="w100 b">原价</td>
        <td class="w100 b">优惠价</td>
        <td class="w100 b">打折</td>
        <td class="w100 b">数量</td>
        <td class="w81 b">删除</td>
      </tr>
       <c:forEach var="list" items="${list }">
      <tr class="h26 blue">
        <td><a href="ShowServlet?wid=${list.wid }" >&nbsp;&nbsp;&nbsp;&nbsp;${list.wname }</a></td>
        <td><span class="c9">￥${list.wprice }</span></td>
        <td><span class="red" >￥${list.wprice*list.wdiscount/100 }</span></td>
        <td><span class="black">${list.wdiscount }%</span></td>
        <td><input onchange="priceCalc();" type="text" value="1" maxlength="4" size="3" id="count"/></td>
        <td><a href="JavaScript:void(0);" onclick="remove(this,${list.cid});" >删除</a></td>
      </tr>
      </c:forEach>
      <tr class="h26">
        <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="IndexServlet">继续挑选商品</a></td>
        <td class="a_c" colspan="2"  class="pl58" id="sum"></td>
        <td colspan="3" id="sum1"></td>
      </tr>
    </tbody>
  	</table>
    <form id="buyForm" method="post" action="PayServelt">
    <table class="buy">    
    <tbody>    
      <tr class="buytitle">
        <td colspan="2" >补充您的邮件地址和联系人基本信息</td>
      </tr>
      <tr>
				<td class="a_r"><label for="username">收件人：</label></td>
        <td><input type="text" name="name" id="name" value="${user.name }" disabled="disabled"/>
			</tr>
      <tr>
				<td class="a_r"><label for="address">地&nbsp;&nbsp;&nbsp;址： </label></td>
        <td id="selectPlace">
        	<input type="text" name="address" id="address" value="${user.address }"/>
        	<a href="javascript:openWindow()" class="b">请点击填写地址</a>
  			</td>
      </tr>      
      <tr>
				<td class="a_r"><label for="tel">电&nbsp;&nbsp;&nbsp;话：</label></td>
        <td><input  type="text" name="code"  maxlength="11" id="tel" value="${user.tel }"/></td>
      </tr>
      <tr>
        <td class="h65">&nbsp;</td>
        <td><input class="imginput" type="image" src="images/submit.gif" /></td>
      </tr>
      </tbody>
  </table>
  </form>    		
		<iframe id="footer" src="footer.jsp" width="980" height="150" frameborder="0" scrolling="no"></iframe>
	</div><!--container	end-->
</body>
